package org.bite.lesson02;

public class Demo_206 {
    public static void main(String[] args) {
        //线程的多种创建方式

        //通过继承Thread类并重写run方法
        MyThread t1 = new MyThread();//任务指定了

        //通过Runnable示例来单独定义线程的任务对象
        MyRunnable r1 = new MyRunnable();
        Thread thread = new Thread(r1);//任务可以更换

        //通过创建Thread匿名内部类的方式创建线程
        Thread thread1 = new Thread(){
            @Override
            public void run(){
                System.out.println("通过Thread匿名内部类的方式创建线程");
            }
        };

        //匿名内部类,Runnable
        Thread thread2 = new Thread(new Runnable(){
            @Override
            public void run(){
                System.out.println("匿名内部类，Runnable……");
            }
        });

        ////通过Lambda表达式创建一个线程
        Thread thread3 = new Thread(()->{
            System.out.println("通过Lambda表达式创建线程……");
        });
    }
}
class MyRunnable implements Runnable{
    @Override
    public void run(){
        System.out.println("hello my Runnable");
    }
}

class MyThread extends Thread{
    @Override
    public void run(){
        System.out.println("hello my Thread");
    }
}
